#include <buola/image/format.h>
#include <buola/image/io.h>
#include <buola/image/drawing/basic.h>
#include <buola/image/adaptors.h>

using namespace buola;

int main()
{
/*    {
        img::CImage_rgb8 lImage({320,200},img::pixel(50,50,50));

        img::draw_frame(lImage,img::pixel(255,100,100));
        auto lView=vflip_view(img::sub_view(lImage,{20,20,300,180}));

        img::CPixel_rgb8 lColor(127,98,200);
        start_timer();
        for(int j=0;j<1000000;j++)
        for(int i=0;i<lView.Height()/2;i++)
        {
            lView(i,i)=lColor;
        }
        end_timer();

        img::draw_frame(lView,img::pixel(255,100,100));

        img::save(lImage,io::file("agg2.png"));
    }
    {
        img::CImage_rgb8 lImage({320,200},img::pixel(50,50,50));

        img::draw_frame(lImage,img::pixel(255,100,100));
        auto lView=vflip_view(img::sub_view(lImage,{20,20,300,180}));

        img::CPixel_rgb8 lColor(127,98,200);
        start_timer();
        for(int j=0;j<1000000;j++)
        for(int i=0;i<lView.Height()/2;i++)
        {
            lView(i,i)=lColor;
        }
        end_timer();

        img::draw_frame(lView,img::pixel(255,100,100));

        img::save(lImage,io::file("agg2.png"));
    }
*/
    {
        img::CImage_rgb8 lImage({320,200},img::pixel(50,50,50));

        img::draw_frame(lImage,img::pixel(255,100,100));
        auto lView=vflip_view(img::sub_view(lImage,{20,20,300,180}));

        start_timer();
        for(int j=0;j<1000000;j++)
        for(int i=0;i<lView.Height()/2;i++)
        {
            lView(i,i)[0]=200;
            lView(i,i)[1]=98;
            lView(i,i)[2]=127;
        }
        end_timer();

        img::draw_frame(lView,img::pixel(255,100,100));

        img::save(lImage,io::file("agg2b.png"));
    }
    {
        img::CImage_gray8 lImage({320,200},img::pixel(50));

        img::draw_frame(lImage,img::pixel(100));
        auto lView=vflip_view(img::sub_view(lImage,{20,20,300,180}));

        img::CPixel_gray8 lColor(200);
        start_timer();
        for(int j=0;j<1000000;j++)
        for(int i=0;i<lView.Height()/2;i++)
        {
            lView(i,i)=lColor;
        }
        end_timer();

        img::draw_frame(lView,img::pixel(100));

        img::save(lImage,io::file("agg2m.png"));
    }
}